package com.ruoyi.quartz.thread;

import com.ruoyi.bizsys.domain.CreditAccount;
import com.ruoyi.business.service.IBLoanInfoService;
import com.ruoyi.business.service.ICollectionService;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;

@Slf4j
public class CollectionTaskThread implements Callable {

    private String threadName;

	private String redisName;
	private RedisCache redisCache;

    private ICollectionService iCollectionService;

    public CollectionTaskThread(String threadName, String redisName,
								ICollectionService iCollectionService, RedisCache redisCache) {
		super();
		this.threadName = threadName;
		this.redisName = redisName;
		this.redisCache = redisCache;
		this.iCollectionService = iCollectionService;
	}

	@Override
	public String toString() {
		return "CollectionTaskThread [threadName=" + threadName+ ", redisName=" + redisName + "]";
	}

	@Override
    public Object call() throws Exception {
        String result = ":success";
		log.info(this.threadName+"=======[START]===" + this.toString());

		List<String> collectCustNos = redisCache.getCacheList(this.redisName);
		log.info("本次有 {} 个催收记录需要执行", collectCustNos.size());
		
        for (String custNo : collectCustNos) {
        	log.info("客户号 {} 开始执行催收跑批操作", custNo);
        	
        	//执行任务
			iCollectionService.dealCollection(custNo);
        	
            log.info("客户号{}执行催收记录跑批操作正常结束", custNo);
        }

		redisCache.deleteObject(this.redisName);

        log.info(this.threadName+"=======[END]===run result:" + result);
        return threadName + result;
    }
}